<template>
  <div>
    <bread>
      <span slot="manage">商品管理</span>
      <span slot="add">添加商品</span>
    </bread>
    <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
      <el-form-item label="商品编码" prop="productId">
        <el-input v-model="ruleForm.productId"></el-input>
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        <el-input v-model="ruleForm.productName"></el-input>
      </el-form-item>
      <el-form-item label="商品价格" prop="productPrice">
        <el-input v-model="ruleForm.productPrice"></el-input>
      </el-form-item>
      <el-form-item label="商品图片" prop="productImage">
        <el-input v-model="ruleForm.productImage"></el-input>
      </el-form-item>
      <el-form-item label="商品链接" prop="productUrl">
        <el-input v-model="ruleForm.productUrl"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">添加商品</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import Bread from '../Bread'
  export default {
    data() {
      return {
        ruleForm: {
          productId: '',
          productName: '',
          productPrice: '',
          productImage: '',
          productUrl: ''
        }
      }
    },
    components: {
      Bread
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
